
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>麦香劳管理后台</title>
<?php include("common/conn.php"); if($_SESSION['userid']==""){echo "<script>window.location.href='login.php';</script>";} 
header('Content-Type:text/html;charset=ytf8');

 
if($_GET['action']=="ok")
{    
	if($_POST[title]!=''||$_POST[top_price]||$_POST[price]||$_POST[number]){
		//全局变量
		$arrType = array('image/jpg', 'image/png', 'image/gif', 'image/png', 'image/bmp', 'image/pjpeg');
		$max_size = '500000000';
		// 最大文件限制（单位：byte）
		$upfile = 'uploads';
		//图片目录路径
		$file = $_FILES['upfile'];
		if ($_SERVER['REQUEST_METHOD'] == 'POST') {
			//判断提交方式是否为POST
			if (!is_uploaded_file($file['tmp_name'])) {
				//判断上传文件是否存在
				echo "<font color='#FF0000'>文件不存在！</font>";
				exit;
			}
			if ($file['size'] > $max_size) {
				//判断文件大小是否大于500000字节
				echo "<font color='#FF0000'>上传文件太大！</font>";
				exit;
			}
			if (!file_exists($upfile)) {
				// 判断存放文件目录是否存在
				mkdir($upfile, 0777, true);
			}
			$imageSize = getimagesize($file['tmp_name']);
			$img = $imageSize[0] . '*' . $imageSize[1];
			$fname = $file['name'];
			$ftype = explode('.', $fname);
			$uptime = date('YmdHis') . rand(100, 999);
			$picName = $upfile . '/' . $uptime . '.' . $ftype[1];
			$sql_picName = 'uploads' . '/' . $uptime . '.' . $ftype[1];
			if (!move_uploaded_file($file['tmp_name'], $picName)) {
				echo "<font color='#FF0000'>移动文件出错！</font>";
				exit;
			} else {
				/*echo "<font color='#FF0000'>图片文件上传成功！</font><br/>";
				  echo "<font color='#0000FF'>图片大小：$img</font><br/>";
				  echo "图片预览：<br><div style='border:#F00 1px solid; width:200px;height:200px'>
				  <img src=\"".$picName."\" width=200px height=200px>".$fname."</div>";*/
			}
		}
		$srat=mysql_query("INSERT INTO coupon(top_price,price,images,title,number) VALUES ('$_POST[top_price]','$_POST[price]','$sql_picName','$_POST[title]','$_POST[number]')");
	}else{
		 echo "<script>alert('请填写完所有信息');window.location.href='discount.php';</script>";
	}
}

if($_GET['id']!=""){


	if($_GET['ch']=="ok")
	{    
		$srat1=mysql_query("update coupon set title='".$_POST['title']."' where couponid='".$_REQUEST['id']."'");
		$srat1=mysql_query("update coupon set top_price='".$_POST['top_price']."' where couponid='".$_REQUEST['id']."'");
		$srat1=mysql_query("update coupon set price='".$_POST['price']."' where couponid='".$_REQUEST['id']."'");
		$srat1=mysql_query("update coupon set number='".$_POST['number']."' where couponid='".$_REQUEST['id']."'");
		//全局变量
		$arrType=array('image/jpg','image/png','image/gif','image/png','image/bmp','image/pjpeg');
		$max_size='500000000';      // 最大文件限制（单位：byte）
		$upfile='uploads'; //图片目录路径
		$file=$_FILES['upfile'];
	  
	   if($_SERVER['REQUEST_METHOD']=='POST'){ //判断提交方式是否为POST
			if(is_uploaded_file($file['tmp_name'])){//判断上传文件是否存在
				   if($file['size']>$max_size){  //判断文件大小是否大于500000字节
						echo "<font color='#FF0000'>上传文件太大！</font>";
						exit;
					}else{
							if(!file_exists($upfile)){  // 判断存放文件目录是否存在
							   mkdir($upfile,0777,true);
							   } 
							   $imageSize=getimagesize($file['tmp_name']);
							   $img = $imageSize[0].'*'.$imageSize[1];
							   $fname = $file['name'];
							   $ftype = explode('.',$fname);
							   $uptime = date('YmdHis').rand(100,999);
							   $picName = $upfile.'/'.$uptime.'.'.$ftype[1];
							   $sql_picName = 'uploads'.'/'.$uptime.'.'.$ftype[1];
							  
							   if(!move_uploaded_file($file['tmp_name'],$picName)){
									echo "<font color='#FF0000'>移动文件出错！</font>";
									exit;
								}else{
									$srat1=mysql_query("update coupon set images='".$sql_picName."' where couponid='".$_REQUEST['id']."'");
									/*echo "<font color='#FF0000'>图片文件上传成功！</font><br/>";
									echo "<font color='#0000FF'>图片大小：$img</font><br/>";
									echo "图片预览：<br><div style='border:#F00 1px solid; width:200px;height:200px'>
									<img src=\"".$picName."\" width=200px height=200px>".$fname."</div>";
									*/
								}

					}
			}

		}
	}
}
?>
<script type="text/javascript" src="js/jquery.min.js"></script>

    <!-- MASTER STYLESHEET-->
    <link href="css/styles.css" rel="stylesheet" type="text/css" />
    
    <!-- LOAD TIPSY TOOLTIPS-->
    <script type="text/javascript" src="js/jquery.tipsy.js"></script>
   
    <!-- LOAD CUSTOM JQUERY SCRIPTS-->
    <script type="text/javascript" src="js/scripts.js"></script>	
    
	 <!-- LOAD FACEBOX -->
	<script type="text/javascript" src="js/facebox.js"></script>
    <link href="css/facebox.css" rel="stylesheet" type="text/css" />
    

    <!-- LOAD FLOT GRAPHS -->
    <script type="text/javascript" src="js/jquery.flot.pack.js"></script>
    <!--[if IE]>
     <script language="javascript" type="text/javascript" src="js/excanvas.pack.js"></script>
    <![endif]-->
    
    
    <!--[if IE 6]>
    <script src="js/pngfix.js"></script>
    <script>
        DD_belatedPNG.fix('.png_bg');
    </script>        
    <![endif]-->

	
    <!-- LOAD GRAPH JAVASCRIPT FILE-->
	<script src="js/graphs.js" type="text/javascript"></script>


</head>

<body>

<div id="header" class="png_bg">

    <div id="head_wrap" class="container_12">
    
        <!-- start of logo - you could replace this with an image of your logo -->
        <div id="logo" class="grid_4">
          <h1>麦香劳管理平台</h1>
        </div>
        <!-- end logo -->
        
        <!-- start control panel -->
    	<div id="controlpanel" class="grid_8">
        
            <ul>
            
    			
                <li><a href="loginout.php" class="last">退出登录</a></li>
                
            </ul>
            
        </div>
        <!-- end control panel -->
    
        <!-- start navigation -->
      	<div id="navigation" class=" grid_12">
           
            <ul>
            
               <li> <a href="index.php" > 订单管理 </a></li>
                <li><a href="goods2.php" class="active" >商品管理</a></li>
				<li><a href="faxian/tryout.php">发现管理</a></li>
                <li><a href="shequ.php">商家管理</a></li>
                <li><a href="user.php">用户管理</a></li><li><a href="huodong.php">社区管理</a></li><li><a href="xitong.php">系统管理</a></li> 
                
    
            </ul>
          
        </div>
        <!-- end navigation -->
     
    </div><!-- end headwarp  -->
</div><!-- end header -->


<!-- staqrt subnav -->
<div id="sub_nav">

<div id="subnav_wrap" class="container_12">
	
    <!-- start sub nav list -->
	<div id="subnav" class=" grid_12">
    
        <ul>
          <li><a href="city.php"  >城市管理</a></li><li> <a href="fenlei.php" > 分类管理 </a></li>
          <li><a href="shequ.php" >商家管理</a></li>
        <li><a href="discount.php" class="sub_nav_active">优惠券管理</a></li>
		  
		</ul>
    
    </div>
    <!-- end subnavigation list -->	

</div>


</div>
<!-- end sub_nav -->

<!-- EVERYTING BELOW IS THE MAIN CONTENT -->

<div class="container_12">
<form action="?<?php if($_GET['id']!=""){echo "ch=ok";}else{echo "action=ok";} ?>&page=<?php echo $_REQUEST[page]; ?>" method="post">
          <h2>添加优惠</h2>  	
    <table width="100%" border="0" cellpadding="0" cellspacing="0">
         
	  
		
        <tr>
        
        

			<tr>
            <th width="20%" scope="col">优惠标题</th>
            <th width="80%" scope="col"><input name="title" type="text"  value="<?php echo $sdg30[title];?>"/></th>
            </tr>
            <tr>
            <th width="20%" scope="col">满多少</th>
            <th width="80%" scope="col"><input name="top_price" type="text"  value="<?php echo $sdg30[top_price];?>"/></th>
            </tr>
            <tr>
            <tr>
            <th width="20%" scope="col">送多少</th>
            <th width="80%" scope="col">
                <input name="price" type="text"  value="<?php echo $sdg30[price];?>"/>

            </th>
            </tr>
			<tr>
            <th width="20%" scope="col">数量</th>
			<th width="80%" scope="col"><input name="number" value="<?php echo $sdg30[number];?>"/></th>
			</tr>
			<tr>
            <th width="20%" scope="col">优惠券图片</th>
            <th width="80%" scope="col">
                <input name="file" type="file" />

            </th>
            </tr>
			<?php if($sdg30[images]!=''){?>
			<tr>
				<th width="20%" scope="col"></th>
				<th width="80%" scope="col">
					<img src="api/<?php echo $sdg30[images];?>" />
				</th>
            </tr>
			<?php }?>
			<tr>
            <th width="20%" scope="col"></th>
			<th width="80%" scope="col"><input name="id" type="hidden" value="<?php echo $_GET[id];?>" /><input name="" type="submit" value="提交" /></th>
			</tr>
            
        </tr>
        
		
    </table>
    </form>
    <!-- END TABULAR DATA EXAMPLE -->
      
           
         

           

           
           
              
          
</div>

<!-- end content wrap -->

</form>
</body>
</html>
